package com.wanli.agent.homepage.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.wanli.agent.R;
import com.wanli.agent.bean.AgentShowBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Author: HWC
 */
public class LookRankListAdapter extends RecyclerView.Adapter<LookRankListAdapter.ViewHolder> {
    private List<AgentShowBean.DataBean> listsBeans;
    private Context context;

    public LookRankListAdapter(List<AgentShowBean.DataBean> listsBeans) {
        this.listsBeans = listsBeans;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
        context = viewGroup.getContext();
        View inflate = LayoutInflater.from(context).inflate(R.layout.item_look_rank, viewGroup, false);
        ViewHolder viewHolder = new ViewHolder(inflate);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        AgentShowBean.DataBean dataBean = listsBeans.get(position);
        holder.tvName.setText(dataBean.getName());
        holder.tvMobile.setText("手机号：" + dataBean.getMobile());
        if (dataBean.getWithdraw_limit() == 1) {
            holder.tvWithdrawLimit.setTextColor(context.getResources().getColor(R.color.theme_color));
            holder.tvWithdrawLimit.setText("提现权限：已限制");
        } else {
            holder.tvWithdrawLimit.setTextColor(context.getResources().getColor(R.color.text_color_5));
            holder.tvWithdrawLimit.setText("提现权限：未限制");
        }
        if (dataBean.getLogin_limit() == 1) {
            holder.tvLoginLimit.setText("登录权限：已限制");
            holder.tvLoginLimit.setTextColor(context.getResources().getColor(R.color.theme_color));
        } else {
            holder.tvLoginLimit.setText("登录权限：未限制");
            holder.tvLoginLimit.setTextColor(context.getResources().getColor(R.color.text_color_5));
        }
        if (dataBean.getIncome_limit() == 1) {
            holder.tvIncomeLimit.setText("进件权限：已限制");
            holder.tvIncomeLimit.setTextColor(context.getResources().getColor(R.color.theme_color));
        } else {
            holder.tvIncomeLimit.setText("进件权限：未限制");
            holder.tvIncomeLimit.setTextColor(context.getResources().getColor(R.color.text_color_5));
        }
        if (dataBean.getInvite_limit() == 1) {
            holder.tvInviteLimit.setText("邀请权限：已限制");
            holder.tvInviteLimit.setTextColor(context.getResources().getColor(R.color.theme_color));
        } else {
            holder.tvInviteLimit.setText("邀请权限：未限制");
            holder.tvInviteLimit.setTextColor(context.getResources().getColor(R.color.text_color_5));
        }
    }

    @Override
    public int getItemCount() {
        return listsBeans.size() == 0 ? 0 : listsBeans.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.tv_name)
        TextView tvName;
        @BindView(R.id.tv_mobile)
        TextView tvMobile;
        @BindView(R.id.tv_withdraw_limit)
        TextView tvWithdrawLimit;
        @BindView(R.id.tv_login_limit)
        TextView tvLoginLimit;
        @BindView(R.id.tv_income_limit)
        TextView tvIncomeLimit;
        @BindView(R.id.tv_invite_limit)
        TextView tvInviteLimit;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
